package com.bayihouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bayihouse.constant.CommonConstant;
import com.bayihouse.mapper.RentinfoMapper;
import com.bayihouse.model.entity.Rentinfo;
import com.bayihouse.model.request.rentinfo.RentinfoQueryRequest;
import com.bayihouse.model.vo.OutPersonVO;
import com.bayihouse.model.vo.RentinfoVO;
import com.bayihouse.service.RentinfoService;
import com.bayihouse.utils.SqlUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author Administrator
* @description 针对表【rentinfo】的数据库操作Service实现
* @createDate 2025-04-23 02:22:33
*/
@Service
public class RentinfoServiceImpl extends ServiceImpl<RentinfoMapper, Rentinfo>
    implements RentinfoService {

    @Override
    public RentinfoVO getRentinfoVO(Rentinfo rentinfo) {
        if (rentinfo == null) {
            return null;
        }
        return RentinfoVO.objToVo(rentinfo);
    }

    @Override
    public Wrapper<Rentinfo> getQueryWrapper(RentinfoQueryRequest rentinfoQueryRequest) {
        Long id = rentinfoQueryRequest.getId();
        Integer price = rentinfoQueryRequest.getPrice();
        String address = rentinfoQueryRequest.getAddress();
        Long displayid = rentinfoQueryRequest.getDisplayid();
        String detail = rentinfoQueryRequest.getDetail();
        String landlordname = rentinfoQueryRequest.getLandlordname();
        String landlordtelephone = rentinfoQueryRequest.getLandlordtelephone();
        Integer status = rentinfoQueryRequest.getStatus();
        Long roomId = rentinfoQueryRequest.getRoomId();
        long current = rentinfoQueryRequest.getCurrent();
        long pageSize = rentinfoQueryRequest.getPageSize();
        String sortField = rentinfoQueryRequest.getSortField();
        String sortOrder = rentinfoQueryRequest.getSortOrder();
        QueryWrapper<Rentinfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(id != null, "id", id);
        queryWrapper.eq(price != null, "price", price);
        queryWrapper.like(StringUtils.isNotBlank(address), "address", address);
        queryWrapper.eq(displayid != null, "displayid", displayid);
        queryWrapper.like(StringUtils.isNotBlank(detail), "detail", detail);
        queryWrapper.like(StringUtils.isNotBlank(landlordname), "landlordname", landlordname);
        queryWrapper.eq(StringUtils.isNotBlank(landlordtelephone), "landlordtelephone", landlordtelephone);
        queryWrapper.eq(status != null, "status", status);
        queryWrapper.eq(roomId != null, "roomId", roomId);
        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
                sortField);
        return queryWrapper;
    }

    @Override
    public List<RentinfoVO> getRentinfoVOList(List<Rentinfo> records) {
        if (CollectionUtils.isEmpty(records)) {
            return new ArrayList<>();
        }
        return records.stream().map(this::getRentinfoVO).collect(Collectors.toList());
    }
}




